]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-app-system: Give priority to .desktop IDs that should be shown
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Thu, 23 Mar 2023 23:25:06 +0000 (00:25 +0100)
committerMarge Bot <marge-bot@gnome.org>
Thu, 20 Apr 2023 15:11:58 +0000 (15:11 +0000)
If we have multiple desktop ID's that share the same startup-wm class
and none of them is actually matching the desktop-id, then we should
exclude the ones that should not be shown in the current desktop.

This will help preventing cases such as the previous one in case no
desktop file ID would match the startup-wm-class exactly.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2721>

src/shell-app-system.c

index e042a6747921cf458447fb50b8f2223697c9669e..29417935131dfbc1435772837546b8e633378562 100644 (file)
@@ -114,17 +114,20 @@ static void
 scan_startup_wm_class_to_id (ShellAppSystem *self)
 {
   ShellAppSystemPrivate *priv = self->priv;
+  g_autoptr(GPtrArray) no_show_ids = NULL;
   const GList *l;
   GList *all;
 
   g_hash_table_remove_all (priv->startup_wm_class_to_id);
 
   all = shell_app_cache_get_all (shell_app_cache_get_default ());
+  no_show_ids = g_ptr_array_new ();
 
   for (l = all; l != NULL; l = l->next)
     {
       GAppInfo *info = l->data;
       const char *startup_wm_class, *id, *old_id;
+      gboolean should_show;
 
       id = g_app_info_get_id (info);
       startup_wm_class = g_desktop_app_info_get_startup_wm_class (G_DESKTOP_APP_INFO (info));
@@ -132,11 +135,23 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
       if (startup_wm_class == NULL)
         continue;
 
+      should_show = g_app_info_should_show (info);
+      if (!should_show)
+        g_ptr_array_add (no_show_ids, (char *) id);
+
       /* In case multiple .desktop files set the same StartupWMClass, prefer
        * the one where ID and StartupWMClass match */
       old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class);
-      if (old_id == NULL ||
-          startup_wm_class_is_exact_match (id, startup_wm_class))
+
+      if (old_id && startup_wm_class_is_exact_match (id, startup_wm_class))
+        old_id = NULL;
+
+      /* Give priority to the desktop files that should be shown */
+      if (old_id && should_show &&
+          g_ptr_array_find_with_equal_func (no_show_ids, old_id, g_str_equal, NULL))
+        old_id = NULL;
+
+      if (!old_id)
         g_hash_table_insert (priv->startup_wm_class_to_id,
                              g_strdup (startup_wm_class), g_strdup (id));
     }